package com.borened.netty.protocol.mqtt;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class MqttClientHandler extends ChannelInboundHandlerAdapter {

    private MqttClientSession client;
    private ChannelHandlerContext ctx;

    public MqttClientHandler(MqttClientSession client, ChannelHandlerContext ctx) {
        this.client = client;
        this.ctx = ctx;
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        client.setChannel(ctx.channel());
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) {
        client.setChannel(null);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}